angular.module('mychat2').factory('socket',['$rootScope',function($rootScope){
	console.log('socket');
	var socket = io();
	socket.on('connected',function(){
		console.log('123');
	})
	return{
		'on':function(eventName,callback){
			console.log('eventName: '+eventName);
			socket.on(eventName,function(){
				var args = arguments;
				$rootScope.$apply(function(){
					callback.apply(socket,args);
				});
			});
		},
		'emit':function(eventName,data,callback){
			console.log('emit'+eventName);
			socket.emit('mychat',{'action':'getRoom'})
			socket.emit(eventName,data,function(){
				var args = arguments;
				$rootScope.$apply(function(){
					if(callback){
						callback.apply(socket,args);
					}
				});
			});
		}
	}

}]);